var pageSizes = {
	"defaultFormat" : null,
	"A4" : { height: '185mm', width: '400mm',  top: '1px' },
	"goTalk4" : { height: '187mm', width: '208mm', top: '15px' },
	"techTalk8" : { height: '184mm', width: '380mm', top: '1px' },
	"goTalk9" : { height: '187mm', width: '208mm', top: '1px' },
	"techSpeak32" : { height: '150mm', width: '350mm', top: '1px' },
	"smartScan8" : { height: '184mm', width: '380mm', top: '1px' }
}

function formatPage(){
	$('.cimg > img').load(function(){
		//console.log('trigger fired');
		adjustRatio($(this));
	});
	
	bindEmbeds();
}

function bindEmbeds(){
	embedElements = document.getElementsByTagName('embed');
		
	if(embedElements.length > 0){

		for(i = 0; i < embedElements.length; i++){
			//console.dir(embedElements[i]);
			embedElements[i].onload = function(){
				adjustRatio($(this));
			};
		}
	}	
}

function adjustRatio(img){
    if(img.parent().innerHeight() < img.height()){
        img.css('height', '100%');
        img.css('width', 'auto');
    }
    else if(img.parent().innerWidth() < img.width()){
        img.css('width', '100%');
        img.css('height', 'auto');
    }
}

function drawPrintGuide(size){
	if(size == null) return;
	var pg = $("<div>", { 'class': 'printGuide' });
	pg.append($('<img>', { 'src': PicBoard.baseURL + 'images/cutout.png' }));
	pg.css({'left': 1, 'top': pageSizes[size].top, 'height': pageSizes[size].height, 'width': pageSizes[size].width});
	pg.insertAfter('#PBchartNameHolder');
}

PicBoard.addLoadEvent( "formatPage()" );